Gradient Boost

Before moving forward with the to-do list, let’s throw a Random Forest to it.

Gradient boost

For many reasons, Random Forest is usually a very good baseline model. In this particular case I started with the polynomial OLS as baseline model, just because it was so evident from the correlations that the relationship between temperature and consumption follows a polynomial shape. But let’s go back to a beloved RF.

Model Cards provide a framework for transparent, responsible reporting. 
 Use the vetiver `.qmd` Quarto template as a place to start, 
 with vetiver.model_card()
Writing pin:
Name: 'wd-gb'
Version: 20241225T130936Z-3746f
<vetiver.vetiver_model.VetiverModel at 0x7f6ffbfb6d10>

Metrics

Single Split CV
train test test train
MAE - Mean Absolute Error 1.338308 1.957019 2.008216 1.252648
MSE - Mean Squared Error 3.415343 14.581645 9.420298 2.921005
RMSE - Root Mean Squared Error 1.848065 3.818592 2.760135 1.708891
R2 - Coefficient of Determination 0.963644 0.807698 -1.560421 0.970137
MAPE - Mean Absolute Percentage Error 0.126990 0.190417 0.326913 0.104553
EVS - Explained Variance Score 0.963644 0.816192 -0.592865 0.970137
MeAE - Median Absolute Error 0.984626 1.374432 1.450955 0.927985
D2 - D2 Absolute Error Score 0.811335 0.681474 -0.375010 0.821694
Pinball - Mean Pinball Loss 0.669154 0.978509 1.004108 0.626324

Scatter plot matrix

Observed vs. Predicted and Residuals vs. Predicted

Check for …

check the residuals to assess the goodness of fit.

  • white noise or is there a pattern?
  • heteroscedasticity?
  • non-linearity?

Normality of Residuals:

Check for …

  • Are residuals normally distributed?

Leverage

Scale-Location plot

Residuals Autocorrelation Plot

Residuals vs Time

Again, overfits a lot.

Parameter: param_model__learning_rate

Parameter: param_model__max_depth

Parameter: param_model__min_samples_leaf

Parameter: param_model__min_samples_split

Parameter: param_model__n_estimators

Parameter: param_model__subsample

Parameter: param_vars__columns

Best model

{'model__learning_rate': 0.1,
 'model__max_depth': 5,
 'model__min_samples_leaf': 5,
 'model__min_samples_split': 48,
 'model__n_estimators': 60,
 'model__subsample': 1,
 'vars__columns': ['rf_tu_mean', 'vp_std_mean']}
Pipeline(steps=[('vars', ColumnSelector(columns=['rf_tu_mean', 'vp_std_mean'])),
                ('model',
                 GradientBoostingRegressor(max_depth=5, min_samples_leaf=5,
                                           min_samples_split=48,
                                           n_estimators=60, random_state=7,
                                           subsample=1))])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.

Metrics

Single Split CV
train test test train
MAE - Mean Absolute Error 1.497514 1.954498 2.096367 1.529375
MSE - Mean Squared Error 4.885483 15.498687 7.782363 5.011953
RMSE - Root Mean Squared Error 2.210313 3.936837 2.645709 2.236219
R2 - Coefficient of Determination 0.947994 0.795604 -1.570973 0.948660
MAPE - Mean Absolute Percentage Error 0.134310 0.190245 0.362744 0.118179
EVS - Explained Variance Score 0.947994 0.805914 -0.281674 0.948660
MeAE - Median Absolute Error 0.991999 1.190978 1.706697 1.030062
D2 - D2 Absolute Error Score 0.788891 0.681885 -0.497699 0.782136
Pinball - Mean Pinball Loss 0.748757 0.977249 1.048183 0.764688

Scatter plot matrix

Observed vs. Predicted and Residuals vs. Predicted

Check for …

check the residuals to assess the goodness of fit.

  • white noise or is there a pattern?
  • heteroscedasticity?
  • non-linearity?

Normality of Residuals:

Check for …

  • Are residuals normally distributed?

Leverage

Scale-Location plot

Residuals Autocorrelation Plot

Residuals vs Time

Compare vanilla vs. tuned

Metrics

Single split

Metrics based on the test set of the single split

Cross validation

Predictions, residuals, observed

next

Time vs. Predicted and Observed

Time vs. Residuals

Model details

Pipeline(steps=[('vars',
                 ColumnSelector(columns=['tt_tu_mean', 'rf_tu_mean', 'td_mean',
                                         'vp_std_mean', 'tf_std_mean'])),
                ('model', GradientBoostingRegressor(random_state=7))])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.
Pipeline(steps=[('vars', ColumnSelector(columns=['rf_tu_mean', 'vp_std_mean'])),
                ('model',
                 GradientBoostingRegressor(max_depth=5, min_samples_leaf=5,
                                           min_samples_split=48,
                                           n_estimators=60, random_state=7,
                                           subsample=1))])
In a Jupyter environment, please rerun this cell to show the HTML representation or trust the notebook.
On GitHub, the HTML representation is unable to render, please try loading this page with nbviewer.org.

TODOs